<template>
	<view class="container">
		<!-- 提现资金 -->
		<view class="paywayItem">
			<u-cell-group v-if='paywayInfo.types' :border='false'>
				<u-cell title="提现账户" value='支付宝' v-if="paywayInfo.types=='ali'" @click='selectPaywayTap' :border='false'></u-cell>
				<u-cell title="提现账户" value="微信" v-if="paywayInfo.types=='wx'" @click='selectPaywayTap' :border='false'></u-cell>
				<u-cell title="提现账户" value="银行卡" v-if="paywayInfo.types=='bank'" @click='selectPaywayTap' :border='false'></u-cell>
			</u-cell-group>
			<view style="width: 700rpx;margin-left: 30rpx;" v-if='!paywayInfo.types' @click='selectPaywayTap'>
				选择收款账户
			</view>
			<view class='right'><u-icon name="arrow-right"></u-icon></view>
		</view>
		<!-- 提现金额 -->
		<view class="confirmPayMoney">
			<text style="font-size: 24rpx;color: #666666;margin-bottom: 20rpx;">可提现购物积分余额{{userInfo.incomes}}</text>
			<text class="title">提现金额</text>
			<view class="input_con">
				<text>¥</text>
				<input type="digit" :value="totalPrice" @input="payMoneyChange" placeholder="请输入提现金额" placeholder-style="font-size: 28rpx" maxlength='10' confirm-type='done'/>
			</view>
			<text style="color: red;font-size: 26rpx;" v-if="!totalPricePass">{{priceRule}}</text>
		</view>
		<view class="message">
			<!-- <text v-if="payWayIndex == 0">本金余额提现免手续费，结算提交后T+1到账，节假日不到账</text> -->
			<text style="color: #d4a781;" v-if="payWayIndex == 0">
				<text v-if="serviceChargeRate>0">收益余额提现收取{{$count.mul(serviceChargeRate, 100)}}%/笔手续费，</text>
				<text>最小提现金额{{serviceCharge_min}}元，最大提现金额{{serviceCharge_max}}元，结算提交后T+1到账，节假日不到账</text>
			</text>
		</view>
		<!-- 提现按钮 -->
		<view class="confirm">
			<jc-button @click='confirmTap' style="margin-top: 100rpx" :width='690' title='确认提现' backgroundColor="#FC5E53"></jc-button>
		</view>
		
	</view>
</template>

<script>
	import {user} from '@/api/user.js'
	import {lessee} from '@/api/lessee.js'
	import {wallet} from '@/api/wallet.js'
	import {
		payway
	} from '@/api/payway.js'
	export default{
		data() {
			return {
				userInfo:{},
				totalPrice: '',
				totalPricePass: true,
				priceRule: "请输入大于零的数字",
				payWayIndex:0,
				lastItem:{},
				paywayInfo: {},
				serviceChargeRate: 0,
				serviceCharge_min: 0,
				serviceCharge_max: 0,
				typeList: [
					{
						name: '支付宝',
						key: 'ali'
					},{
						name: '微信',
						key: 'wx'
					},{
						name: '银行卡',
						key: 'bank'
					}]
			}
		},
		onLoad() {
			this.findDefaultPayway()
		},
		onShow() {
			this.getUserInfo()
		},
		methods:{
			getUserInfo() {
				user.getUserInfo().then(res => {
					if (res.data.code == 10000) {
						var userInfo = res.data.data
						// userInfo.incomesPass = this.$count.sub(userInfo.incomes, userInfo.incomesLocked)
						userInfo.bankInfo = userInfo.bankName + ' ' + userInfo.bankAccount
						this.userInfo = userInfo
						this.getItemById()
					}
				})
			},
			getItemById() {
				lessee.getItemById().then(res => {
					if (res.data.code == 10000) {
						this.serviceChargeRate = res.data.data.serviceChargeRate
						this.serviceCharge_min = res.data.data.serviceCharge_min
						this.serviceCharge_max = res.data.data.serviceCharge_max
					}
				})
			},
			//完善会员资料
			setMemberInfo(){
				this.$Router.push({
					name: 'updateBankInfo'
				})
			},
			//选择到账卡
			selecttOutMoneyCart(){
				
			},
			//确认提现金额
			payMoneyChange(e){
				var value = e.detail.value.replace(/\s/g, "")
				if(isNaN(value)){
					this.totalPricePass = false
				}else{
					this.totalPricePass = true
				}
				if(value){
					this.totalPrice = parseFloat(value)
				}else{
					this.totalPrice = 0
				}
			},
			//确认提现按钮
			confirmTap(){
				// if(!this.paywayInfo.id){
				// 	this.$show.showMessage('请选择收款账户')
				// 	return
				// }
				if(!this.totalPrice){
					this.$show.showMessage('请输入提现金额')
					return
				}
				let priceStr = String(this.totalPrice)
				var totalPriceList = priceStr.split('.')
				if(totalPriceList.length>2){
					this.$show.showMessage('输入金额格式不正确')
					return
				}
				if(totalPriceList.length==2 && totalPriceList[1].length>2){
					this.$show.showMessage('输入金额格式不正确，请保留小数点后两位')
					return
				}
				var that = this
				wallet.outMoneyForUser({
					paywayType: 'incomes',
					payWayId: this.paywayInfo.id,
					payMoney: this.totalPrice,
				}).then(res => {
					if(res.data.code == 10000){
						uni.showModal({
							title: "已发起提现申请，预计两个工作日到账",
							confirmText: "确定",
							showCancel: false,
							success(res_) {
								if(res_.confirm){
									uni.navigateBack({
										
									})
								}
							}
						})
					}
				})
			},
			//获取默认提现方式
			findDefaultPayway(){
				let that = this
				payway.findDefaultPayway().then(res => {
					if(res.data.code == 10000){
						this.paywayInfo = res.data.data
					}
				})
			},
			selectPaywayTap(){
				this.$Router.push({
					name: 'paywayList',
					params: {
						fromWay: 'outMoney'
					}
				})
			},
			//选择提现方式回调
			selectPaywayInfoBack(e){
				console.log('选择地址回调', e)
				this.paywayInfo = JSON.parse(decodeURIComponent(e))
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container{
	}
	.paywayItem{
		margin-top: 20rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		background-color: #FFFFFF;
		padding: 30rpx 0rpx;
		padding-right: 20rpx;
		.center{
			width: 750rpx;
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			.contactInfo{
				display: flex;
				flex-direction: row;
				align-items: center;
				.default{
					background-color: #FC5E53;
					color: #FFFFFF;
					font-size: 20rpx;
					width: 50rpx;
					height: 30rpx;
					margin-right: 10rpx;
					text-align: center;
					font-weight: bold;
				}
				text{
					margin-top: 10rpx;
				}
			}
			.paywayInfo{
				display: flex;
				flex-direction: column;
				align-items: flex-start;
			}
			.right{
				margin-right: 30rpx;
			}
		}
	}
	.payway_cont{
		background-color: #FFFFFF;
		margin-top: 30rpx;
		.content_item{
			display: flex;
			flex-direction: row;
			align-items: center;
			padding: 0 30px;
			.left{
				.isSelect{
					width: 36rpx;
					height: 36rpx;
					padding: 10rpx;
				}
			}
			.right{
				width: 100%;
				display: flex;
				flex-direction: column;
				margin-left: 20rpx;
				padding: 30rpx 0;
			}
			.bottomLine{
				border-bottom: 1px solid #EFEFEF
			}
		}
	}
	.confirmPayMoney{
		margin-top: 20rpx;
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		background-color: #FFFFFF;
		.title{
			font-size: 32rpx;
		}
		.input_con{
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 40rpx;
			// border-bottom: 1px #EFEFEF solid;
			text{
				margin-right: 20rpx;
				font-size: 44rpx;
				font-weight: bold;
			}
			input{
				width: 100%;
				font-size: 34rpx;
			}
		}
		text{
			
		}
	}
	.message{
		color: $st-color-primary;
		font-size: 22rpx;
		margin-top: 20rpx;
		padding: 0 20rpx;
	}
	.confirm{
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
</style>
